from selenium.webdriver.support.wait import WebDriverWait


class BaseAction(object):

    def __init__(self, driver):
        self.driver = driver

    def find_element(self, feature, time=10, poll=0.1):
        # return self.driver.find_element(*feature)
        return WebDriverWait(self.driver, time, poll).until(lambda x: x.find_element(*feature))

    def find_elements(self, feature, time=10, poll=0.1):
        return WebDriverWait(self.driver, time, poll).until(lambda x: x.find_elements(*feature))

    # 点击  定位 调用点击方法
    def click(self, feature, time=10, poll=0.1):
        self.find_element(feature, time, poll).click()

    # 输入
    def send_keys(self, feature, text, time=10, poll=0.1):
        self.find_element(feature, time, poll).send_keys(text)

    # 获取文本
    def get_text(self, feature, time=10, poll=0.1):
        return self.find_element(feature, time, poll).text

    # 清空
    def clear(self, feature, time=10, poll=0.1):
        return self.find_element(feature, time, poll).clear()
